package test;

import src.TinyThreadPool;
public class BootStrap {

    public static void main(String[] args) {
        BootStrap bootStrap = new BootStrap();
        bootStrap.testTinyThreadPool();
    }
    public void testTinyThreadPool(){
        TinyThreadPool pool = new TinyThreadPool(2, 4, 10);
        // 提交任务
        for (int i = 0; i < 10; i++) {
            final int taskId = i;
            pool.execute(() -> {
                System.out.println(Thread.currentThread().getName() +
                        " executing task " + taskId);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            });
        }
        System.out.printf("线程池中线程数量:%s\n",pool.getThreadSize());
        // 关闭线程池
        try {
            Thread.sleep(5000);
            pool.shutdown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
